<template>
  <MSelect v-bind="{ ...config, ...$attrs }"></MSelect>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { apiGetSpaceCarListFast } from '@/api/car';
  import MSelect from '../MSelect/index.vue';

  const config = ref({
    placeholder: '请选择',
    api: (params: any) => {
      if (!params.plan_begin_time || !params.plan_end_time) {
        return new Promise<any>((resolve) => {
          resolve({ data: [] });
        });
      }
      return apiGetSpaceCarListFast({ ...params }).then((res) => {
        res.data = res.data.map((t) => {
          return {
            ...t,
            car_number: `${t.car_number} - ${t.driver_name} - ${t.car_type} - ${t.phone}`,
          };
        });

        return res;
      });
    },
    valueField: 'car_id',
    labelField: 'car_number',
  });
</script>
